import matplotlib.pyplot as plt
import pandas as pd
import warnings
warnings.filterwarnings("ignore")   # 忽略警告信息输出



# 预设图像各种信息
large = 22
med = 16
small = 12
params = {'axes.titlesize': med,  # 子图上的标题字体大小
          'legend.fontsize': med,  # 图例的字体大小
          'figure.figsize': (20, 12),  # 画布大小
          'axes.labelsize': small,  # 标签的字体大小
          'xtick.labelsize': small,  # x轴标尺的字体大小
          'ytick.labelsize': small,  # y轴标尺的字体大小
          'figure.titlesize': large}  # 整个画布的标题字体大小
plt.rcParams.update(params)  # 设定各种默认属性
plt.style.use('seaborn-whitegrid')  # 设置整体风格
# 为了画图中文可以正常显示
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei'] #指定默认字体
plt.rcParams['axes.unicode_minus'] = False  #解决保存图像时负号'-'显示为方块的问题
# 读取数据
construction = pd.read_excel(r'城建.xlsx',names=['city','road','efflurnt','water'])

plt.figure(figsize=(10,5))
# 绘制办公用品的气泡图
plt.scatter(x = construction.road[construction.city == '北京'],
            y = construction.efflurnt[construction.city == '北京'],
            s =2*construction.water[construction.city == '北京'] ,
            color = 'steelblue', label = '北京', alpha = 0.6
            )
plt.scatter(x = construction.road[construction.city == '上海'],
            y = construction.efflurnt[construction.city == '上海'],
            s =2*construction.water[construction.city == '上海'] ,
            color = 'black', label = '上海', alpha = 0.6
            )
plt.scatter(x = construction.road[construction.city == '广州'],
            y = construction.efflurnt[construction.city == '广州'],
            s =2*construction.water[construction.city == '广州'] ,
            color = 'green', label = '广州', alpha = 0.6
            )
plt.scatter(x = construction.road[construction.city == '深圳'],
            y = construction.efflurnt[construction.city == '深圳'],
            s =2*construction.water[construction.city == '深圳'] ,
            color = 'red', label = '深圳', alpha = 0.6
            )
plt.scatter(x = construction.road[construction.city == '武汉'],
            y = construction.efflurnt[construction.city == '武汉'],
            s =2*construction.water[construction.city == '武汉'] ,
            color = 'darkorange', label = '武汉', alpha = 0.6
            )
plt.scatter(x = construction.road[construction.city == '南京'],
            y = construction.efflurnt[construction.city == '南京'],
            s =2*construction.water[construction.city == '南京'] ,
            color = 'purple', label = '南京', alpha = 0.6
            )

# 添加x轴和y轴标签
plt.xlabel('人均道路面积（㎡）')
plt.ylabel('废水处理率（%）')
# 添加标题
plt.title('人均道路面积、废水处理率和人均用水量的对比')
# 添加图例
plt.legend()
# 显示图形
plt.show()
